< previous page page_299 next page >

Page 299
column. This is important to understand. Using columns that contain a limited set of data (such as months of the year) produces valuable result sets. However, using a column that contains unique data (such as the CustomerID column) produces a result set with an unpredictable number of columns.
The nice thing about TRANSFORM_PIVOT is that it is easy to produce several different views of the same data by just changing the PIVOT column. For example, what if you wanted to see the book sales results by BookSales.SaleRep instead of by BookSales.Qtr? All you have to do is change the PIVOT field. See the following code example and Figure 8.34.
TRANSFORM SUM(BookSales.Sales)
   SELECT Title FROM BookSales
   GROUP BY Title
PIVOT BookSales.SalesRep
0299-01.jpg
Figure 8.34.
Changing the PIVOT field.
Notice, in Figure 8.34, that you can see a column with the header <>. When Microsoft Access Jet ran the SQL statement, it discovered some records that had no value in the BookSales.SaleRep column. SQL automatically created a new column (<>) to hold these records and make sure they were not left out of the result set.
Even though TRANSFORM_PIVOT is a powerful SQL tool, there is one drawback to its widespread use in your programs. The TRANSFORM_PIVOT clause is not an ANSI-SQL clause. Microsoft added this clause as an extension of the ANSI-SQL command set. If you use it in your programs, you will not be able to port your SQL statements to other back-end databases that do not support the TRANSFORM_PIVOT SQL clause. Despite this drawback, you will find TRANSFORM_PIVOT a very valuable SQL tool when it comes to producing result sets for summary reports, data graphs, and charts.

 
< previous page page_299 next page >

If you like this book, buy it!